package com.example.system.controller.sysuser;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.vo.LoginUserVO;
import com.example.common.security.service.TokenService;
import com.example.system.domain.sysuser.dto.LoginDTO;
import com.example.system.domain.sysuser.dto.SysUserSaveDTO;
import com.example.system.domain.sysuser.vo.SysUserVo;
import com.example.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员接口") // @Tag打标签用于接口分组的
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private TokenService tokenService;

    @Value("${jwt.secret}")
    private String secret;


    @Operation(summary = "管理员登陆",description = "根据账号密码进行管理员登录")

    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toR(sysUserService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.info(token);
    }


    @Operation(summary = "新增管理员",description = "根据提供的账户名密码新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysUserSaveDTO sysUserSaveDTO){

        return toR(sysUserService.add(sysUserSaveDTO));
    }


    @Operation(summary = "删除管理员",description = "根据提供的管理员ID删除管理员")
    @Parameters(value = {
            @Parameter(name = "userId",in = ParameterIn.PATH,description = "用户ID")
    })
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @DeleteMapping("/{userId}")
    public R<Void> delete(@PathVariable Long userId){
        return null;
    }

    @Operation(summary = "查询管理员详情" ,description = "根据提供的查询条件查询管理员详情")
    @Parameters( value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "用户ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "用户性别")
    })
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @GetMapping("/detail")
    private R<SysUserVo> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex){ //参数的必传和非必穿
        return null;
    }


}
